<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="admin/common/header::common-head">
    <!--<#include "../common/header.html">-->
</head>
<body>
    <!--边栏-->
    <!--<#include "../common/nav.html">-->
    <div th:replace="admin/common/nav::common-nav" ></div>
    <script src="https://cdn.bootcss.com/twitter-bootstrap/3.0.1/js/bootstrap.min.js"></script>

    <div class="content-wrapper" style="width: auto">
        <div class="container" style="max-width: 1500px">
            <div class="row clearfix">
                <div class="col-md-12 column">
                    <div name="search" class="col-md-8 row-md-8">
                        <div class="input-group">
                            <select id="searchType" class="btn btn-primary" style="width: 80px;text-align: center;">
                                <option class="btn btn-primary" value="名称">名称</option>
                                <option class="btn btn-primary" value="编号">编号</option>
                            </select>
                            <input class="form-control" type="text" placeholder="Search for..." id="search">
                            <span class="input-group-btn">
                                    <button class="btn btn-primary" type="button" id="enterSearch" onclick="searchProduct()">
                                        <i class="fa fa-search"></i>
                                    </button>
                                 </span>
                            &nbsp;&nbsp;&nbsp;&nbsp;
                            <button type="button" class="btn btn-lg active"><a href="/fashionpress/product/add"> 添加商品</a></button>
                            <button type="button" class="btn btn-lg active" th:if="${productStatus==null||productStatus==0}"><a href="/fashionpress/product/list?productStatus=1"> 下架商品列表</a></button>
                            <button type="button" class="btn btn-lg active" th:if="${productStatus!=null&&productStatus==1}"><a href="/fashionpress/product/list?productStatus=0"> 上架商品列表</a></button>
                        </div>
                    </div>
                    <table class="table">
                        <thead>
                            <tr>
                                <th>
                                    商品编号
                                </th>
                                <th>
                                    商品图片
                                </th>
                                <th>
                                    商品名称
                                </th>
                                <th>
                                    商品单价
                                </th>
                                <th>
                                    商品库存
                                </th>
                                <th>
                                    商品销量
                                </th>
                                <th>
                                    商品简介
                                </th>
                                <th>
                                    商品状态
                                </th>
                                <th>
                                    商品分类
                                </th>
                                <th>
                                    操作
                                </th>
                            </tr>
                        </thead>
                        <tbody>

                            <tr class="success" th:each="productVO:${productVOs}" >
                                <td th:text="${productVO.productId}">

                                </td>
                                <td>
                                    <img th:src="@{/admin/jpg/{imgUrl}(imgUrl=${productVO.getImgs().get(0)})}" style="width: 60px; height: 60px;">

                                </td>
                                <td th:text="${productVO.productName}">

                                </td>
                                <td th:text="${productVO.productPrice}">

                                </td>
                                <td th:text="${productVO.productInventory}">

                                </td>
                                <td th:text="${productVO.productSales}">

                                </td>
                                <td th:text="${productVO.productDescribe}">
                                </td>
                                <td th:if="${productVO.productStatus==0}">
                                    上架
                                </td>
                                 <td th:if="${productVO.productStatus==1}">
                                    下架
                                </td>
                                <td th:text="${productVO.category.categoryName}">
                                </td>
                                <td th:if="${productVO.productStatus==0}">
                                    <button type="button" class="btn active updateProductStatus"><a th:href="@{/product/updateProductStatus/{productId}(productId=${productVO.productId})}">下架</a></button>
                                    <button type="button" class="btn active"><a th:href="@{/product/update/{productId}(productId=${productVO.productId})}">修改</a></button>
                                </td>
                                <td th:if="${productVO.productStatus==1}">
                                    <button type="button" class="btn active updateProductStatus"><a th:href="@{/product/updateProductStatus/{productId}(productId=${productVO.productId})}">上架</a></button>
                                    <button type="button" class="btn active"><a th:href="@{/product/update/{productId}(productId=${productVO.productId})}">修改</a></button>
                                </td>

                            </tr>

                        </tbody>
                    </table>

                </div>
            </div>
        </div>
        <link rel="stylesheet" type="text/css" media="screen" href="/fashionpress/admin/css/pagination.css">
        <div class="container">
            <div class="row clearfix">
                <div class="col-md-12 column">
                    <ul class="pagination pull-right pages"   th:if="${pagenum!=null&&totalPage!=null}">
                        <li th:if="${pagenum<=1}" >
                            <a href="#" >Prev</a>
                        </li>
                        <li th:if="${pagenum>1}" >
                            <a th:href="@{/product/list/(productStatus=${productStatus},pagenum=${pagenum}-1)}">Prev</a>
                        </li>

                        <li th:each="index:${#numbers.sequence(1,totalPage)}">
                            <a th:href="@{/product/list/(productStatus=${productStatus},pagenum=${index})}"><span th:class="${index==pagenum?'active':''}" th:text="${index}"></span></a>
                        </li>

                        <li th:if="${pagenum==totalPage}">
                            <a href="#">Next</a>
                        </li>
                        <li th:if="${pagenum<totalPage}">
                            <a th:href="@{/product/list/(productStatus=${productStatus},pagenum=${pagenum}+1)}">Next</a>
                        </li>
                    </ul>
                </div>
            </div>
        </div>



        <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
        <script>
            function searchProduct() {
                var serch = document.getElementById("search");
                if (document.getElementById("searchType").value=="名称"){
                    var url = "/fashionpress/product/selectByName/"+serch.value;
                    window.location.href=url;
                }
                if (document.getElementById("searchType").value=="编号"){
                    var url = "/fashionpress/product/selectById/"+serch.value;
                    window.location.href=url;
                }

            }
            $(document).ready(function () {
                $(".updateProductStatus").click(function () {
                    $msg = "您确定要修改？"
                    if (confirm($msg)==true)
                        return true;
                    else{
                        return false;
                    }
                })
            });
        </script>

    </div>
    <div th:replace="admin/common/footer::common-footer"/>
</body>
</html>